<template>
	<view class="report-content" :style="[{backgroundImage:'url(https://txr001.zthj.net/static/img/sjtbBg.png)'}]">
		<cu-custom :isBack="true" style="background-color: transparent;">
			<block slot="content">
				<view class="custom-title">数据填报</view>
			</block>
		</cu-custom>
		<view class="filling-content">
			<image src="https://txr001.zthj.net/static/img/sjtbIMg.png" class="sjtb-img"></image>
			<view class="center-content" v-if="currentIndex==1">
				<view class="top-content">
					<view class="left">填空题</view>
					<view class="right">必填</view>
				</view>
				<view class="question-title">1、本次填报企业主体名称</view>
				<view class="margin-top-48">
					<input placeholder="请填写企业名称" v-model="company_name" class="input-class"></input>
				</view>
			</view>
			<view class="center-content" v-if="currentIndex==index+2" v-for="(item,index) in question" :key="index">
				<view class="top-content">
					<view class="left" v-if="item.qusetion_type=='0'">填空题</view>
					<view class="left" v-else>选择题</view>
					<view class="right">必填</view>
				</view>
				<view class="question-title">{{index+2}}、{{item.subject}}</view>
				<view class="margin-top-48" v-if="item.qusetion_type=='0'">
					<input class="input-class" v-model="answer[index]"></input>
				</view>
				<view v-else>
					<view :class="pick==option_idex?'pick':'choice'" @tap="choose(option_idex,index)"
						v-for="(option_item,option_idex) in item.option" :key="option_idex">{{option_item}}</view>

				</view>
			</view>

			<view @click="complate">
				<image src="https://txr001.zthj.net/static/img/xyt.png" class="xyt-img"></image>
			</view>
			<view class="bottom-text">
				青牒碳账户提供技术支持
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				question: [],
				currentIndex: 1,
				pick: -1,
				company_name: '',
				answer: [],
				wenjuan_id: 0
			};
		},
		onLoad: function(e) {
			if (e.wenjuan_id) {
				this.wenjuan_id = e.wenjuan_id;
				this.getQuestion(e.wenjuan_id);
			}
		},
		methods: {
			getQuestion: async function(id) {
				let res = await this.$api.question({
					id: id
				});
				// console.log(res);
				this.question = res;
			},
			choose: function(option_index, index) {
				this.pick = option_index;
				this.answer[index] = this.question[index].option[option_index];
			},
			async complate() {
				// console.log(this.answer);
				if (this.currentIndex == this.question.length + 1) {
					let res = await this.$api.jisuan({
						wenjuan_id:this.wenjuan_id,
						answer :this.answer,
						company_name:this.company_name
					});
					if(res.code==1){
						uni.navigateTo({
							url: "/pages/carAccount/report?score="+res.data
						});
					}
					
					return false;
				}
				this.pick = -1;
				this.currentIndex++;
			}


		}
	}
</script>
<style lang="less" scoped>
	.report-content {
		background-size: 100% 100%;
		width: 100%;
		height: 1620rpx;

		.filling-content {
			padding: 126rpx 32rpx 0;

			.sjtb-img {
				width: 334rpx;
				height: 156rpx;
			}

			.center-content {
				height: 760rpx;
				margin-top: 76rpx;
				background: #FFFFFF;
				border-radius: 52rpx;
				padding: 32rpx;

				.top-content {
					width: 188rpx;
					height: 44rpx;
					line-height: 44rpx;
					border-radius: 8rpx;
					border: 2rpx solid #4690F7;
					display: flex;
					align-items: center;
					text-align: center;

					.left {
						width: 108rpx;
						height: 44rpx;
						background: #4690F7;
						border-radius: 8rpx;
						font-size: 28rpx;
						font-weight: 500;
						color: #FFFFFF;
					}

					.right {
						padding: 0 8rpx;
						font-size: 28rpx;
						font-weight: 500;
						color: #4690F7;
					}
				}

				.question-title {
					font-size: 32rpx;
					font-weight: 500;
					color: #000000;
					margin-top: 24rpx;
				}

				.input-class {
					width: 100%;
					height: 80rpx;
					background: #FFFFFF;
					border-radius: 24rpx;
					border: 2rpx solid #666666;
					padding-left: 40rpx;
				}
			}
		}

		.xyt-img {
			margin-top: 38rpx;
			width: 100%;
			height: 132rpx;
		}

		.bottom-text {
			font-size: 24rpx;
			font-weight: 400;
			color: #656565;
			text-align: center;
			margin-top: 40rpx;
		}

		.pick {
			color: #FFFFFF !important;
			background-color: #008AFF !important;
			width: 85%;
			border-radius: 20rpx;
			padding: 20rpx 20rpx;
			// margin-top: 30rpx;
			// height: 150rpx;
			font-size: 26rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			margin: 30rpx auto;
			// padding: 0rpx 5rpx;
		}

		.choice {
			color: #2B2E3D !important;
			background-color: #F7F8FA !important;
			width: 85%;
			border-radius: 20rpx;
			padding: 20rpx 20rpx;
			// margin-top: 30rpx;
			// height: 150rpx;
			font-size: 26rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			text-align: left;
			margin: 30rpx auto;
		}
	}
</style>